/* 
 * [New BSD License (BSD 3-Clause License)]
 * Copyright (c) 2012, Max Bechtold
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * 
 *     - Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     - Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     - Neither the name of the Rel2Xml Project nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package maxbe.rel2xml.generator.docs.constraints;

import java.util.List;

import maxbe.rel2xml.generator.docs.DataType;

/**
 * Interface describing types of ValueConstructors, see package
 * maxbe.rel2xml.for implementations
 * 
 * @author Max Bechtold
 * 
 */
public interface ValueConstructor {

	/**
	 * States whether this ValueConstructor needs to be announced the total
	 * number of tuples. If so, a table owning it has to precalulate its final
	 * cardinality which may imply generating lots of int factors (if the
	 * respective table is dependent on another one).
	 */
	public boolean needsAnnounce();

	/**
	 * Announces the total number of values that this constructor has to be able
	 * to deliver. This allows the preparation of values in advance for
	 * constructors that have a global context and are not affected by the mark
	 * method.
	 * 
	 * @param number
	 *            total number of tuples
	 */
	public void announce(int number);

	/**
	 * States whether this ValueConstructor has a varying length
	 * 
	 * @return true if length varies
	 */
	public boolean lengthVaries();

	/**
	 * Returns the length of this ValueConstructor. If {@link #lengthVaries()}
	 * returns true, this is the maximum length. If length has no meaning, -1
	 * will be returned.
	 * 
	 * @return length or -1 if there is no length
	 */
	public int getLength();

	/**
	 * Returns the subsidiary length of this ValueConstructor or -1 if that is
	 * no applicable property
	 * 
	 * @return subsidiary length or -1 if there is none
	 */
	public int getSubLength();

	/**
	 * Returns a list of DataTypes that this ValueConstructor supports.
	 * 
	 * @return list of supported DataTypes
	 */
	public List<DataType> getSupportedDataTypes();

	/**
	 * Announces the number of upcoming values to be fetched in a new context
	 * (i.e. for a new tuple of a parent table or of a table this table depends
	 * on. This has no effect on constructors that have a global context
	 * 
	 * @param number
	 *            number of tuples in new context
	 */
	public void mark(int number);

	// TODO what happens after all values have been fetched? Exception?
	/**
	 * Generates a value according to this ValueConstructor's construction
	 * rules.
	 * 
	 * @return generated value
	 */
	public String next();

	/**
	 * Generates a list of <tt>number</tt> values according to this
	 * ValueConstructor's construction rules.
	 * 
	 * @param number
	 *            number of values to generate
	 * @return list of generated values
	 */
	public List<String> next(int number);

}
